package fr.generali.accueilclient.gwt.showcase.client.form.subforms;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import fr.generali.accueilclient.gwt.client.ui.components.form.ListBox;

public class PhoneFormItem extends Composite {

    private static PhoneFormItemUiBinder uiBinder = GWT.create(PhoneFormItemUiBinder.class);

    interface PhoneFormItemUiBinder extends UiBinder<Widget, PhoneFormItem> {
    }

    @UiField
    SubFormResource res;
    
    @UiField
    ListBox<String> phoneType;
    
    @UiField
    Label rowLabel;
    
    public PhoneFormItem() {
        initWidget(uiBinder.createAndBindUi(this));
        res.style().ensureInjected();
        initPhoneTypes();
    }

    private void initPhoneTypes() {
        phoneType.addItem("-");
        phoneType.addItem("Fax");
        phoneType.addItem("Fixe");
        phoneType.addItem("Portable");
    }

    public void setLabel(String Label) {
        rowLabel.setText(Label);
    }
    
    public void setInError(boolean inError) {
        if (inError) {
            phoneType.addStyleName(res.style().error());
        } else {
            phoneType.removeStyleName(res.style().error());
        }
    }
}
